package com.hong.spring.mvc.controller;

import com.hong.spring.mvc.bean.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Auther: csh
 * @Date: 2020/7/23 09:52
 * @Description:该控制器主要用于 @PathVaiable 学习
 */
@Controller
public class PathVariableController {
    /**
     *
     * 功能描述:通过传入值获取
     *
     * @param:
     * @return:
     * @auther: csh
     * @date: 2020/7/26 9:39
     */
    @RequestMapping("/{id}")
    public String showUserInfo(ModelMap modelMap, @PathVariable("id")Integer id){
        Student student = new Student();
        student.setId(id);
        student.setAge(100);
        student.setName("test");
        modelMap.addAttribute("name", student.getName());
        modelMap.addAttribute("age", student.getAge());
        modelMap.addAttribute("id", student.getId());
        return "result";
    }
    /**
     *
     * 功能描述:跳转首页
     *
     * @param:
     * @return:
     * @auther: csh
     * @date: 2020/7/26 9:39
     */
    @RequestMapping("/redirect")
    public String redirect(){
        return "redirect:home";
    }

}
